from myPsychology.odmantic.mongoDB_models import Scale


class ScaleRepository:

    def __init__(self, engine):
        self.engine = engine

    async def get_scale_by_name(self, name: str) -> Scale:
        scale = await self.engine.find_one(Scale, Scale.chinese_name == name)
        return scale

    async def get_scale_by_abbr(self, abbr: str) -> Scale:
        scale = await self.engine.find_one(Scale, Scale.abbreviation == abbr)
        return scale

    async def get_all_scales(self) -> list:
        scales = await self.engine.find(Scale, sort=Scale.abbreviation)
        return scales
